range01 <- function(x) {
  (x - min(x, na.rm=TRUE)) / diff(range(x, na.rm=TRUE))
}

stan_violence$vote_import <- range01(6- stan_violence$vote_importance)

figures10 <- ggplot()+
  geom_smooth(data = stan_violence %>% filter(days < 1), aes(days, vote_import), method = 'loess', color = '#3838d9', fill = "#3838d9", span = 2)+
  geom_smooth(data = stan_violence %>% filter(days > -1 & days < 40), aes(days, vote_import), method = 'loess', color = '#3838d9', fill = "#3838d9", span = 2)+
  theme_bw()+
  geom_vline(xintercept = 0, color = 'red', linetype=2)+
  # coord_cartesian(ylim = c(0,0.4))+
  scale_x_continuous(breaks = seq(-40,40,5))+
  xlab('Days before/after 2022 Election')+
  ylab('Vote Importance')

suppressMessages(print(figures10))
#ggsave(file = 'vote_importance.png', units = 'in', height = 8, width = 10)